/**
 * Created by pankajmishra on 15/01/15.
 */
define(['jquery','mustache', 'module/home/customEvent'], function($, Mustache, customEvent){
    return function(detailid){

        $.ajax({
            url: '/user/getDiscussionDetail', data: {
                id : detailid
            }, dataType: "json"
        }).done(
            function(update){
                $.event.trigger({
                    type: customEvent.FREE_MENU,
                    append: true
                });
                var template = require('module/template/homeTemplate');
                var item = update[0];
                item['commentCount'] = function(){
                    return this.comments?this.comments.length:0;
                }
                var discussionhtml = $(Mustache.to_html(template['discussion-detail'], item));
                $('.main-content').empty();
                $('.main-content').append(discussionhtml);




                require(['module/home/showUpdateComments', 'module/home/showCommentBox'],
                    function(showUpdateComments, showCommentBox){
                        var ul = discussionhtml.find(".list-group");
                        showCommentBox(discussionhtml.find(".fakecomment"),
                        {callback: showUpdateComments, commentDomParent : ul, parentId: detailid});
                        showUpdateComments(item.comments, ul);
                });
            }
        );
    };
});
